package com.tamtamy.jtta.conf;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import com.tamtamy.jtta.constant.Type;
import com.tamtamy.jtta.exception.LoadPropertiesException;

public class JTTAProperties extends Properties {
	
	private static final long serialVersionUID = 7478893066503503966L;
	
	public final static String APP_NAME = "jTTA";
	public final static String REQUEST_XML 	= ".xml";
	public final static String REQUEST_JSON = ".json";
	
	private String version = "0.2";
    private String type = Type.XML;
    private boolean debug = false;
    private boolean ssl = false;
    
    private String apiUrl = "beta.tamtamy.com";
    private String apiUsername = null;
    private String apiPassword = null;
    
	public JTTAProperties(String propertiesFile) throws LoadPropertiesException {
		super();  			  			  
		try {
			File configurationFile = null;
			configurationFile = new File(propertiesFile);
			this.load(new FileInputStream(configurationFile));
			System.out.println("Properties File Path: " + configurationFile.getAbsolutePath());		  
			version = this.getProperty("version");		  		  		    
			type = this.getProperty("type");
			debug = Boolean.parseBoolean(this.getProperty("debug"));
			apiUsername = this.getProperty("apiUsername");
			apiPassword = this.getProperty("apiPassword");
			apiUrl = this.getProperty("apiUrl");
			ssl = Boolean.parseBoolean(this.getProperty("ssl"));
			System.out.println("defaults values");	
		} catch (FileNotFoundException fileNotFoundException) {
			throw new LoadPropertiesException("Cannot find properties file " + propertiesFile, fileNotFoundException);
		} catch (IOException ioException) {
			throw new LoadPropertiesException("Cannot find properties file " + propertiesFile, ioException);
		}

	}

	public String getApiUrl() {
		return apiUrl;
	}

	public void setApiUrl(String apiUrl) {
		this.apiUrl = apiUrl;
	}

	public String getApiUsername() {
		return apiUsername;
	}

	public void setApiUsername(String apiUsername) {
		this.apiUsername = apiUsername;
	}

	public String getApiPassword() {
		return apiPassword;
	}

	public void setApiPassword(String apiPassword) {
		this.apiPassword = apiPassword;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public boolean isDebug() {
		return debug;
	}

	public void setDebug(boolean debug) {
		this.debug = debug;
	}

	public boolean isSsl() {
		return ssl;
	}

	public void setSsl(boolean ssl) {
		this.ssl = ssl;
	}
	
}
